<template>
    <nav class="nav">
        <div class="nav_box">
            <a href="#" class="logo">
                <img src="../assets/image/logo.png" alt="">
            </a>
            <el-menu :default-active="activeMenu"
                     class="el-menu"
                     mode="horizontal"
                     background-color="#f58f98"
                     text-color="#fff"
                     active-text-color="#C4727A"
                     @select="handleSelect">

                <el-menu-item v-for="(item,index) in routes" :key="index" :index="item.name" class="hoverStyle"><a
                        :href="item.path">{{item.meta.title}}</a>
                    <i class="el-icon-caret-top triangle" v-if="item.name==activeMenu"></i>
                </el-menu-item>

            </el-menu>
            <div class="login">
               <span class="login_content">
                   <a href="/login">登录</a>
                   <i>|</i>
                    <a href="/register">注册</a>
               </span>
            </div>
        </div>
    </nav>
</template>

<script>
    export default {
        name: "topNav",
        data() {
            return {
                activeIndex: 0,
            }
        },
        computed: {
            routes() {

                return this.$router.options.routes.filter((item) => {
                    return item.isNav && !item.admin;
                })
            },
            activeMenu() {
                const route = this.$route
                const {name} = route
                // if set path, the sidebar will highlight the path you set

                return name
            },
        },
        mounted() {
            console.log(this.$router.options.routes)
        },
        methods: {
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
            }
        }
    }
</script>
<style>
    .nav .el-menu.el-menu--horizontal {

        height: 66px;
        border-bottom: none;
        margin-left: 20px;

    }
</style>
<style scoped lang="scss">
    @import "../styles/comment.scss";

    $height: 66px;
    .nav {
        width: 100%;
        height: $height;
        background-color: $backgroundColor;

        .nav_box {
            width: 1200px;
            min-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            .login{
                width: 138px;
                margin-top: 3px;
                /*height: 50px;*/
                .login_content{
                    display: inline-block;
                    vertical-align: top;
                    border-radius: 20px;
                    background: rgba(0, 0, 0, 0.2);
                    color: #fff!important;
                    line-height: 35px;
                    padding-left: 15px;
                    padding-right: 15px;
                    i{
                        margin:15px;
                    }
                }
            }
            .logo {
                display: inline-block;
                width: 180px;
                height: 66px;
            }

            .el-menu {
                background-color: $backgroundColor;

                li {
                    height: 100%;
                    line-height: $height;

                    &.is-active {
                        background-color: $navHoverColor !important;
                    }
                     .triangle{
                         position: absolute;
                         bottom:-8px;
                         left: 50%;
                         transform: translateX(-12px);
                         color: #fff;
                     }
                    a {
                        color: $navFontColor;
                        display: inline-block;
                        width: 100%;
                        height: 100%;
                    }
                }
            }
        }

    }
</style>
